from django.contrib import admin
from django.utils.translation import gettext_lazy as _
from django.contrib.auth.admin import UserAdmin
from .models import User, Radiologist, Schedule, Leave, UnforeseenCircumstance, Study, Workload

class CustomUserAdmin(UserAdmin):
    fieldsets = UserAdmin.fieldsets + (
        (_('Дополнительная информация'), {
            'fields': ('role',),
        }),
    )
    list_display = ('username', 'email', 'role', 'is_staff', 'is_active')
    list_filter = ('role', 'is_staff', 'is_active')

admin.site.register(User, CustomUserAdmin)

class RadiologistAdmin(admin.ModelAdmin):
    list_display = ('first_name', 'last_name', 'modality', 'position', 'rate', 'tab_number', 'working_hours')
    search_fields = ('first_name', 'last_name', 'modality')
    list_filter = ('modality', 'position')

    fieldsets = [
        (None, {'fields': ('first_name', 'last_name', 'middle_name', 'modality', 'additional_modalities', 'position', 'rate', 'tab_number', 'working_hours', 'full_month_hours')}),
    ]
    verbose_name = _('Врач-рентгенолог')
    verbose_name_plural = _('Врачи-рентгенологи')

admin.site.register(Radiologist, RadiologistAdmin)

class ScheduleAdmin(admin.ModelAdmin):
    list_display = ('radiologist', 'date', 'shift_start', 'shift_end', 'worked_hours', 'is_approved')
    search_fields = ('radiologist__first_name', 'radiologist__last_name', 'date')
    list_filter = ('date', 'is_approved')

    fieldsets = [
        (None, {'fields': ('radiologist', 'date', 'shift_start', 'shift_end', 'break_duration', 'worked_hours', 'is_approved')}),
    ]
    verbose_name = _('Расписание')
    verbose_name_plural = _('Расписания')

admin.site.register(Schedule, ScheduleAdmin)

class LeaveAdmin(admin.ModelAdmin):
    list_display = ('radiologist', 'leave_type', 'start_date', 'end_date')
    search_fields = ('radiologist__first_name', 'radiologist__last_name', 'leave_type')
    list_filter = ('leave_type', 'start_date')

    fieldsets = [
        (None, {'fields': ('radiologist', 'leave_type', 'start_date', 'end_date')}),
    ]
    verbose_name = _('Отпуск')
    verbose_name_plural = _('Отпуска')

admin.site.register(Leave, LeaveAdmin)

class UnforeseenCircumstanceAdmin(admin.ModelAdmin):
    list_display = ('radiologist', 'date', 'reason')
    search_fields = ('radiologist__first_name', 'radiologist__last_name', 'reason')
    list_filter = ('date',)

    fieldsets = [
        (None, {'fields': ('radiologist', 'date', 'reason')}),
    ]
    verbose_name = _('Непредвиденное обстоятельство')
    verbose_name_plural = _('Непредвиденные обстоятельства')

admin.site.register(UnforeseenCircumstance, UnforeseenCircumstanceAdmin)

class StudyAdmin(admin.ModelAdmin):
    list_display = ('year', 'week_number', 'modality', 'quantity', 'ue_per_study', 'is_with_contrast', 'is_multiple_zones')
    search_fields = ('year', 'week_number', 'modality')
    list_filter = ('year', 'modality', 'is_with_contrast', 'is_multiple_zones')

    fieldsets = [
        (None, {'fields': ('year', 'week_number', 'modality', 'quantity', 'ue_per_study', 'is_with_contrast', 'is_multiple_zones')}),
    ]
    verbose_name = _('Исследование')
    verbose_name_plural = _('Исследования')

admin.site.register(Study, StudyAdmin)

class WorkloadAdmin(admin.ModelAdmin):
    list_display = ('year', 'week_number', 'modality', 'predicted_quantity', 'actual_quantity', 'predicted_ue', 'actual_ue')
    search_fields = ('year', 'week_number', 'modality')
    list_filter = ('year', 'modality')

    fieldsets = [
        (None, {'fields': ('year', 'week_number', 'modality', 'predicted_quantity', 'actual_quantity', 'predicted_ue', 'actual_ue')}),
    ]
    verbose_name = _('Нагрузка')
    verbose_name_plural = _('Нагрузки')

admin.site.register(Workload, WorkloadAdmin)